home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_7_3a.arc / MOUSE.CPP < prev    next >
C/C++ Source or Header  |  1989-02-20  |  2KB  |  121 lines

  1. // mouse.cpp    implements methods for the Mouse class. see "mouse.cls".
  2. //
  3. // (c) Aspen Scientific 1989. All Rights Reserved.
  4. // Author: Vaughn Vernon
  5.  
  6. #include "mouse.cls"
  7.  
  8. // ************************************************************
  9. // ** the Mouse methods in this file are implemented for MS-DOS
  10. // ** in a text display (non-graphics) environment.  it uses
  11. // ** 8086 interrupts and the Microsoft C int86() function.
  12. // ************************************************************
  13.  
  14. #include <dos.h>
  15.  
  16. static union REGS mRegs;
  17. static union REGS holdForEvent;
  18.  
  19. Mouse::Mouse()
  20. {
  21.     mRegs.x.ax = 0;
  22.     int86(0x33, &mRegs, &mRegs);
  23.  
  24.     // AX == 0 means mouse not installed
  25.     if (mRegs.x.ax == 0)
  26.         installed = 0;
  27.     else {
  28.         installed = 1;
  29.         numButtons   = mRegs.x.bx;
  30.  
  31.         // set the text software cursor
  32.         // and make all characters pointed
  33.         // to reverse-video.
  34.         mRegs.x.ax = 10;
  35.         mRegs.x.bx = 0;
  36.         mRegs.x.cx = 0x00ff;
  37.         mRegs.x.dx = 0x7000;
  38.         int86(0x33, &mRegs, &mRegs);
  39.  
  40.         show();
  41.         flush();
  42.     }
  43. }
  44.  
  45. Mouse::~Mouse()
  46. {
  47.     if (installed) {
  48.  
  49.         // under ms-mouse and dos, re-initializing
  50.         // shuts things down
  51.         mRegs.x.ax = 0;
  52.         int86(0x33, &mRegs, &mRegs);
  53.     }
  54. }
  55.  
  56. void
  57. Mouse::hide()
  58. {
  59.     if (installed) {
  60.         mRegs.x.ax = 2;
  61.         int86(0x33, &mRegs, &mRegs);
  62.     }
  63. }
  64.  
  65. void
  66. Mouse::show()
  67. {
  68.     if (installed) {
  69.         mRegs.x.ax = 1;
  70.         int86(0x33, &mRegs, &mRegs);
  71.     }
  72. }
  73.  
  74. int
  75. Mouse::getEvent(Point & p, unsigned & b1, unsigned & b2, unsigned & b3)
  76. {
  77.     if (!installed)
  78.         return 0;
  79.  
  80.     mRegs.x.ax = 3;
  81.     int86(0x33, &mRegs, &mRegs);
  82.  
  83.     if (mRegs.x.bx == holdForEvent.x.bx &&
  84.         mRegs.x.cx == holdForEvent.x.cx &&
  85.         mRegs.x.dx == holdForEvent.x.dx)
  86.         return 0;
  87.  
  88.     holdForEvent = mRegs;
  89.  
  90.     // vertical and horizontal cursor poition
  91.     p(mRegs.x.dx / 8, mRegs.x.cx / 8);
  92.  
  93.     // are the buttons down?
  94.     b1 = (mRegs.x.bx & 0x01) ? 1:0;
  95.     b2 = (mRegs.x.bx & 0x02) ? 1:0;
  96.     b3 = 0;
  97.  
  98.     return 1;
  99. }
  100.  
  101. void
  102. Mouse::setPosition(Point & p)
  103. {
  104.     if (installed) {
  105.         mRegs.x.ax = 4;
  106.         mRegs.x.cx = p.y();
  107.         mRegs.x.dx = p.x();
  108.         int86(0x33, &mRegs, &mRegs);
  109.     }
  110. }
  111.  
  112. void
  113. Mouse::flush()
  114. {
  115.     Point p;
  116.     unsigned b1, b2, b3;
  117.  
  118.     while (getEvent(p, b1, b2, b3))
  119.         ;
  120. }
  121.